package com.toby.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

/**
 * @desc: 日志切面，演示动态代理调用
 * @author: jonathan.zhang
 * @date: 2019/9/2 18:20
 */
@Aspect
@Component
public class LogAspect {

    @Pointcut("execution(* com.toby.service.UserService.*(..))")
    public void pointCut(){}

    @Before("pointCut()")
    public void before(){
        System.out.println("--------before--------");
    }

    @After("pointCut()")
    public void after(){
        System.out.println("--------after--------");
    }

    @AfterThrowing("pointCut()")
    public void afterThrowing(){
        System.out.println("--------afterThrowing--------");
    }

    @AfterReturning("pointCut()")
    public void afterReturning(){
        System.out.println("--------afterReturning--------");
    }

    @Around("pointCut()")
    public Object around(ProceedingJoinPoint pjp) throws Throwable {
        System.out.println("--------start around--------");
        Object retVal = pjp.proceed(pjp.getArgs());
        System.out.println("--------end around--------");
        return retVal;
    }
}
